%To process the cable data provided by Andres Figoli
load C:\Manoj\projects\cable\AndresFigoli\Figoli_cable_data.mat;
load C:\Manoj\projects\cable\AndresFigoli\SJGdata;

%convert to volts from kv
bocah = bocah*1e3;
bocai = bocai*1e3;
puertok = puertok*1e3;
sanh = sanh*1e3;
%remove long periods from the data by fitting splines

% tide_fday = floor(tide(:,1)*10000)/10000;
% [a,ia,ib] = unique(tide_fday);
% tide_new = tide(ia,:);
% tide_new(5:9:end,:) = [];
fday_s = 1:length(bocah);
[p,s] = polyfit(fday_s,bocah',20);
y_bocah = polyval(p,fday_s);
plot(fday_bocah,bocah-y_bocah','b'); hold on;

fday_s = 1:length(bocai);
[p,s] = polyfit(fday_s,bocai',20);
y_bocai = polyval(p,fday_s);
plot(fday_bocai,bocai-y_bocai','r');

fday_s = 1:length(puertok);
[p,s] = polyfit(fday_s,puertok',20);
y_puertok = polyval(p,fday_s);
plot(fday_puertok,puertok-y_puertok','g');

fday_s = 1:length(sanh);
[p,s] = polyfit(fday_s,sanh',3);
y_sanh = polyval(p,fday_s);
plot(fday_sanh,sanh-y_sanh','k');

legend('BOCA RATON H','BOCA RATON I','PUERTO K','SAN JUAN H');
plot(fday_sjg,sjg_mag_data(:,4)-nanmean(sjg_mag_data(:,4)),'b','LineWidth',2)
plot(fday_sjg,sjg_mag_data(:,2)-nanmean(sjg_mag_data(:,2)),'r','LineWidth',2)
datetick;